package com.cn.springcloudwechat.controller.articleAndMenu;

import com.cn.springcloudwechat.common.ajax.AjaxRes;
import com.cn.springcloudwechat.common.mybatis.Page;
import com.cn.springcloudwechat.common.utils.base.Const;
import com.cn.springcloudwechat.model.articleAndMenu.YmVideoKnowledge;
import com.cn.springcloudwechat.service.articleAndMenu.YmVideoKnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 视频知识Controller
 *
 * @author: Administrator
 * @create: 2018/8/1 16:41
 */
@RestController
@RequestMapping(value = "/web/video/")
public class YmVideoKnowledgeControllerWeb {
    @Autowired
    YmVideoKnowledgeService ymVideoKnowledgeService;

    /**
     * 添加视频
     *
     * @param ajaxRes
     * @param ymVideoKnowledge
     * @return
     */
    @PostMapping(value = "insertViode")
    public AjaxRes insertViode(AjaxRes ajaxRes, YmVideoKnowledge ymVideoKnowledge) {
       Long videoId= ymVideoKnowledgeService.insertSelective(ymVideoKnowledge);
        ajaxRes.setSucceed(videoId);
        return ajaxRes;
    }

    /**
     * 更新视频
     *
     * @param ajaxRes
     * @param ymVideoKnowledge
     * @return
     */
    @PostMapping(value = "updateViode")
    public AjaxRes updateViode(AjaxRes ajaxRes, YmVideoKnowledge ymVideoKnowledge) {
        ymVideoKnowledgeService.updateByPrimaryKeySelective(ymVideoKnowledge);
        ajaxRes.setSucceedMsg(Const.UPDATE_SUCCEED);
        return ajaxRes;
    }

    /**
     * 查询单个视频
     *
     * @param ajaxRes
     * @param videoId
     * @return
     */
    @GetMapping(value = "selectViode")
    public AjaxRes selectViode(AjaxRes ajaxRes, long videoId) {
        YmVideoKnowledge ymVideoKnowledge = ymVideoKnowledgeService.selectByPrimaryKey(videoId);
        ajaxRes.setSucceed(ymVideoKnowledge);
        return ajaxRes;
    }

    /**
     * 查询所有视频
     *
     * @param ajaxRes
     * @return
     */
    @GetMapping(value = "getAllYmVideoKnowledge")
    public AjaxRes getAllYmVideoKnowledge(AjaxRes ajaxRes) {
        List<YmVideoKnowledge> ymVideoKnowledge = ymVideoKnowledgeService.getAllYmVideoKnowledge();
        ajaxRes.setSucceed(ymVideoKnowledge);
        return ajaxRes;
    }

    /**
     * 根据条件查询视频
     *
     * @param record
     * @param page
     * @return
     */
    @GetMapping(value = "getYmVideoKnowledge")
    public AjaxRes getAllYmVideoKnowledgeByParameter(AjaxRes ajaxRes, YmVideoKnowledge record, Page<Object> page) {
        Page<Object> ymVideoKnowledges= ymVideoKnowledgeService.getAllYmVideoKnowledgeByParameter(record, page);
        ajaxRes.setSucceed(ymVideoKnowledges);
        return ajaxRes;
    }


    /**
     * 批量更新视频状态
     * @param ajaxRes
     * @param videoId
     * @param state
     * @return
     */
    @PostMapping(value = "updateYmVideoKnowledgeState")
    public AjaxRes updateYmVideoKnowledgeState(AjaxRes ajaxRes,@RequestParam("videoIds") List<Long> videoId, @RequestParam short state) {
        ymVideoKnowledgeService.updateYmVideoKnowledgeState(videoId, state);
        ajaxRes.setSucceed(Const.UPDATE_SUCCEED);
        return ajaxRes;
    }





}
